home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / MPlay / mpeg_play2.0 / video.h < prev   
Encoding:
C/C++ Source or Header  |  1995-12-08  |  10.8 KB  |  284 lines

  1. /*
  2.  * Copyright (c) 1992 The Regents of the University of California.
  3.  * All rights reserved.
  4.  * 
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose, without fee, and without written agreement is
  7.  * hereby granted, provided that the above copyright notice and the following
  8.  * two paragraphs appear in all copies of this software.
  9.  * 
  10.  * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  11.  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  12.  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  13.  * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  14.  * 
  15.  * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  16.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  17.  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  18.  * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  19.  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  20.  */
  21. #include <stdio.h>
  22. #include <sys/param.h>
  23. #include <setjmp.h>
  24.  
  25. #ifdef SH_MEM
  26. #include <sys/ipc.h>
  27. #include <sys/shm.h>
  28. #include <X11/extensions/XShm.h>
  29. #endif
  30.  
  31. /* X11/xmd.h correctly defines INT32, etc */
  32. #ifndef XMD_H
  33. typedef int INT32;
  34. typedef short INT16;
  35. typedef char INT8;
  36. #endif
  37. typedef unsigned int UINT32;
  38. typedef unsigned short UINT16;
  39. typedef unsigned char UINT8;
  40.  
  41. /* Define Parsing error codes. */
  42.  
  43. #define SKIP_PICTURE -10
  44. #define SKIP_TO_START_CODE -1
  45. #define PARSE_OK 1
  46.  
  47. /* Define BOOLEAN, TRUE, and FALSE. */
  48.  
  49. #define BOOLEAN int
  50. #define TRUE 1
  51. #define FALSE 0
  52.  
  53. /* Set ring buffer size. */
  54.  
  55. #define RING_BUF_SIZE 5 
  56.  
  57. /* Macros for picture code type. */
  58.  
  59. #define I_TYPE 1
  60. #define P_TYPE 2
  61. #define B_TYPE 3
  62.  
  63. /* Start codes. */
  64.  
  65. #define SEQ_END_CODE 0x000001b7
  66. #define SEQ_START_CODE 0x000001b3
  67. #define GOP_START_CODE 0x000001b8
  68. #define PICTURE_START_CODE 0x00000100
  69. #define SLICE_MIN_START_CODE 0x00000101
  70. #define SLICE_MAX_START_CODE 0x000001af
  71. #define EXT_START_CODE 0x000001b5
  72. #define USER_START_CODE 0x000001b2
  73.  
  74. /* Number of macroblocks to process in one call to mpegVidRsrc. */
  75.  
  76. #define MB_QUANTUM 100
  77.  
  78. /* Macros used with macroblock address decoding. */
  79.  
  80. #define MB_STUFFING 34
  81. #define MB_ESCAPE 35
  82.  
  83. /* Lock flags for pict images. */
  84.  
  85. #define DISPLAY_LOCK 0x01
  86. #define PAST_LOCK 0x02
  87. #define FUTURE_LOCK 0x04
  88.  
  89. #define HYBRID_DITHER 0
  90. #define HYBRID2_DITHER 1
  91. #define FS4_DITHER 2
  92. #define FS2_DITHER 3
  93. #define FS2FAST_DITHER 4
  94. #define Twox2_DITHER 5
  95. #define GRAY_DITHER 6
  96. #define FULL_COLOR_DITHER 7
  97. #define NO_DITHER 8
  98. #define ORDERED_DITHER 9
  99. #define MONO_DITHER 10
  100. #define MONO_THRESHOLD 11
  101. #define ORDERED2_DITHER 12
  102. #define MBORDERED_DITHER 13
  103.  
  104. /* External declaration of row,col to zig zag conversion matrix. */
  105.  
  106. extern int scan[][8];
  107.  
  108. /* Temporary definition of time stamp structure. */
  109.  
  110. typedef int TimeStamp;
  111.  
  112. /* Structure with reconstructed pixel values. */
  113.  
  114. typedef struct pict_image {
  115.   unsigned char *luminance;              /* Luminance plane.   */
  116.   unsigned char *Cr;                     /* Cr plane.          */
  117.   unsigned char *Cb;                     /* Cb plane.          */
  118.   unsigned char *display;                /* Display plane.     */
  119.   unsigned char *m_display;              /* malloc'ed Display  */
  120.   int locked;                            /* Lock flag.         */
  121.   TimeStamp show_time;                   /* Presentation time. */
  122.  
  123. #ifdef SH_MEM
  124.   XShmSegmentInfo shminfo;               /* Segment info.  */
  125.   XImage *ximage;                        /* Ximage struct. */
  126. #endif
  127.  
  128. } PictImage;
  129.  
  130. /* Group of pictures structure. */
  131.  
  132. typedef struct GoP {
  133.   BOOLEAN drop_flag;                     /* Flag indicating dropped frame. */
  134.   unsigned int tc_hours;                 /* Hour component of time code.   */
  135.   unsigned int tc_minutes;               /* Minute component of time code. */
  136.   unsigned int tc_seconds;               /* Second component of time code. */
  137.   unsigned int tc_pictures;              /* Picture counter of time code.  */
  138.   BOOLEAN closed_gop;                    /* Indicates no pred. vectors to
  139.                         previous group of pictures.    */
  140.   BOOLEAN broken_link;                   /* B frame unable to be decoded.  */
  141.   char *ext_data;                        /* Extension data.                */
  142.   char *user_data;                       /* User data.                     */
  143. } GoP;
  144.  
  145. /* Picture structure. */
  146.  
  147. typedef struct pict {
  148.   unsigned int temp_ref;                 /* Temporal reference.             */
  149.   unsigned int code_type;                /* Frame type: P, B, I             */
  150.   unsigned int vbv_delay;                /* Buffer delay.                   */
  151.   BOOLEAN full_pel_forw_vector;          /* Forw. vectors specified in full
  152.                         pixel values flag.              */
  153.   unsigned int forw_r_size;              /* Used for vector decoding.       */
  154.   unsigned int forw_f;                   /* Used for vector decoding.       */
  155.   BOOLEAN full_pel_back_vector;          /* Back vectors specified in full 
  156.                         pixel values flag.              */
  157.   unsigned int back_r_size;              /* Used in decoding.               */
  158.   unsigned int back_f;                   /* Used in decoding.               */
  159.   char *extra_info;                      /* Extra bit picture info.         */
  160.   char *ext_data;                        /* Extension data.                 */
  161.   char *user_data;                       /* User data.                      */
  162. } Pict;
  163.  
  164. /* Slice structure. */
  165.  
  166. typedef struct slice {
  167.   unsigned int vert_pos;                 /* Vertical position of slice. */
  168.   unsigned int quant_scale;              /* Quantization scale.         */
  169.   char *extra_info;                      /* Extra bit slice info.       */
  170. } Slice;
  171.  
  172. /* Macroblock structure. */
  173.  
  174. typedef struct macroblock {
  175.   int mb_address;                        /* Macroblock address.              */
  176.   int past_mb_addr;                      /* Previous mblock address.         */
  177.   int motion_h_forw_code;                /* Forw. horiz. motion vector code. */
  178.   unsigned int motion_h_forw_r;          /* Used in decoding vectors.        */
  179.   int motion_v_forw_code;                /* Forw. vert. motion vector code.  */
  180.   unsigned int motion_v_forw_r;          /* Used in decdoinge vectors.       */
  181.   int motion_h_back_code;                /* Back horiz. motion vector code.  */
  182.   unsigned int motion_h_back_r;          /* Used in decoding vectors.        */
  183.   int motion_v_back_code;                /* Back vert. motion vector code.   */
  184.   unsigned int motion_v_back_r;          /* Used in decoding vectors.        */
  185.   unsigned int cbp;                      /* Coded block pattern.             */
  186.   BOOLEAN mb_intra;                      /* Intracoded mblock flag.          */
  187.   BOOLEAN bpict_past_forw;               /* Past B frame forw. vector flag.  */
  188.   BOOLEAN bpict_past_back;               /* Past B frame back vector flag.   */
  189.   int past_intra_addr;                   /* Addr of last intracoded mblock.  */
  190.   int recon_right_for_prev;              /* Past right forw. vector.         */
  191.   int recon_down_for_prev;               /* Past down forw. vector.          */
  192.   int recon_right_back_prev;             /* Past right back vector.          */
  193.   int recon_down_back_prev;              /* Past down back vector.           */
  194. } Macroblock;
  195.  
  196. /* Block structure. */
  197.  
  198. typedef struct block {
  199.   short int dct_recon[8][8];             /* Reconstructed dct coeff matrix. */
  200.   short int dct_dc_y_past;               /* Past lum. dc dct coefficient.   */
  201.   short int dct_dc_cr_past;              /* Past cr dc dct coefficient.     */
  202.   short int dct_dc_cb_past;              /* Past cb dc dct coefficient.     */
  203. } Block;
  204.  
  205. /* Video stream structure. */
  206.  
  207. typedef struct vid_stream {
  208.   unsigned int h_size;                         /* Horiz. size in pixels.     */
  209.   unsigned int v_size;                         /* Vert. size in pixels.      */
  210.   unsigned int mb_height;                      /* Vert. size in mblocks.     */
  211.   unsigned int mb_width;                       /* Horiz. size in mblocks.    */
  212.   unsigned char aspect_ratio;                  /* Code for aspect ratio.     */
  213.   unsigned char picture_rate;                  /* Code for picture rate.     */
  214.   unsigned int bit_rate;                       /* Bit rate.                  */
  215.   unsigned int vbv_buffer_size;                /* Minimum buffer size.       */
  216.   BOOLEAN const_param_flag;                    /* Contrained parameter flag. */
  217.   unsigned char intra_quant_matrix[8][8];      /* Quantization matrix for
  218.                           intracoded frames.         */
  219.   unsigned char non_intra_quant_matrix[8][8];  /* Quanitization matrix for 
  220.                           non intracoded frames.     */
  221.   char *ext_data;                              /* Extension data.            */
  222.   char *user_data;                             /* User data.                 */
  223.   GoP group;                                   /* Current group of pict.     */
  224.   Pict picture;                                /* Current picture.           */
  225.   Slice slice;                                 /* Current slice.             */
  226.   Macroblock mblock;                           /* Current macroblock.        */
  227.   Block block;                                 /* Current block.             */
  228.   int state;                                   /* State of decoding.         */
  229.   int bit_offset;                              /* Bit offset in stream.      */
  230.   unsigned int *buffer;                        /* Pointer to next byte in
  231.                           buffer.                    */
  232.   int buf_length;                              /* Length of remaining buffer.*/
  233.   unsigned int *buf_start;                     /* Pointer to buffer start.   */
  234.   int max_buf_length;                          /* Max lenght of buffer.      */
  235.   PictImage *past;                             /* Past predictive frame.     */
  236.   PictImage *future;                           /* Future predictive frame.   */
  237.   PictImage *current;                          /* Current frame.             */
  238.   PictImage *ring[RING_BUF_SIZE];              /* Ring buffer of frames.     */
  239. } VidStream;   
  240.  
  241. /* Declaration of global pointer to current video stream. */
  242.  
  243. extern VidStream *curVidStream;
  244.  
  245. /* Shared memory flag. */
  246. extern int shmemFlag;
  247.  
  248. /* Quiet mode flag. */
  249. extern int quietFlag;
  250.  
  251. /* Dither flags external declaration. */
  252. extern char *ditherFlags;
  253.  
  254. /* Definition of Contant integer scale factor. */
  255.  
  256. #define CONST_BITS 13
  257.  
  258. /* Misc DCT definitions */
  259. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  260. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  261.  
  262. #define GLOBAL            /* a function referenced thru EXTERNs */
  263.   
  264. typedef short DCTELEM;
  265. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  266.  
  267.  
  268. #ifdef SH_MEM
  269. extern int gXErrorFlag;
  270. #endif
  271.  
  272. extern double realTimeStart;
  273. extern int totNumFrames;
  274. extern int loopFlag;
  275. extern int noDisplayFlag;
  276. extern jmp_buf env;
  277.  
  278. #ifdef ANALYSIS
  279. extern unsigned int bitCount;
  280. extern int showEachFlag;
  281. extern unsigned int cacheHit[8][8];
  282. extern unsigned int cacheMiss[8][8];
  283. #endif
  284.